mod front;
mod backend;
mod ir;
mod parse;

use std::fs;
use std::io::{Read};
use crate::backend::Backend;
use crate::front::Front;


enum InputType{
    FPC4501
}

enum OutputType{
    Sunxi
}

fn main() -> std::io::Result<()> {
    // 文件路径
    let file_path = "template/FPC4501MRYG ILI9806E_HSD4.5_C0423 IPS MIPI双通道.C";

    // 打开文件
    let mut file = fs::File::open(file_path)?;

    // 创建一个足够大的缓冲区来存储文件内容
    let mut contents = String::new();

    // 读取文件内容到缓冲区
    file.read_to_string(&mut contents)?;

    let front: Box<dyn Front> = Box::new(front::FPC4501MRYG_40C_MIPI{});
    // let backend: Box<dyn Backend> = Box::new(backend::SunXi{});
    let backend: Box<dyn Backend> = Box::new(backend::Rockchip{});


    let ir = front.parse(contents.as_str());
    let out_str = backend.gen(&ir);

    let name = "out.c";

    _ = fs::remove_file(name);

    fs::write(name, out_str)?;

    Ok(())
}